﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using DAL;

namespace BUS
{
    public class BAI_VIETBUS
    {
        public static void insert(BAI_VIET bv)//thêm sản phẩm
        {
            BAI_VIETDAL bvdal = new BAI_VIETDAL();
            bvdal.Insert(bv);
        }

        public static void update(BAI_VIET bv)
        {
            BAI_VIETDAL bvdal = new BAI_VIETDAL();
            bvdal.Update(bv);
        }

        public static void update_status(BAI_VIET bv)
        {

            BAI_VIETDAL bvdal = new BAI_VIETDAL();
            bvdal.Update_status(bv);
        }

        public static void Delete(int id)
        {

            BAI_VIETDAL bvdal = new BAI_VIETDAL();
            bvdal.Delete(id);
        }
        public static int CheckExist(int id)
        {
            int t = 0;
            BAI_VIETDAL bv = new BAI_VIETDAL();



            bv.Get("Where MA_BV = " + id.ToString(), 0, 0, Baivietcolum.MA_BV.ToString(), "ASC", out t);
            return t;
        }
        public static Baivetcollection GET(string Where, int PageIndex, int PageSize,
                                       string OrderBy, string OrderDirection,
                                       out int TotalRecords)
        {

            BAI_VIETDAL bvdal = new BAI_VIETDAL();
            return bvdal.Get(Where, PageIndex, PageSize,
                            OrderBy, OrderDirection, out TotalRecords);
        }

        public static Baivetcollection GetAll()
        {
            int t = 0;
            BAI_VIETDAL bvdal = new BAI_VIETDAL();
            return bvdal.Get("where 1=1", 0, 1000,
               Baivietcolum.MA_BV.ToString(), "DESC", out t);

        }
        public static BAI_VIET GetByID(int iD)
        {
            int t = 0;
            BAI_VIETDAL baivietdal = new BAI_VIETDAL();
            Baivetcollection BVcollection = baivietdal.Get("where " + Baivietcolum.MA_BV.ToString() + " = " + iD.ToString(), 0, 0,
                Baivietcolum.TEN_BAI_VIET.ToString(), "ASC", out t);
            if (BVcollection.Count == 1)
                return BVcollection[0];
            return null;
        }
        public static string GetCha(int maloaicha)
        {
            int t = 0;
            BAI_VIETDAL baivietdal = new BAI_VIETDAL();
            Baivetcollection bvcollection = baivietdal.Get("where " + Baivietcolum.MA_BV.ToString() + " = " + maloaicha.ToString(), 0, 0,
                Baivietcolum.MA_BV.ToString(), "ASC", out t);
            if (bvcollection.Count == 1)
                return bvcollection[0].Tenbv;
            return null;
        }
    }
}
